package com.jiawen.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@Api(description = "微服务测试接口")
@RestController
public class LoginController {

    private static final Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private RestTemplate restTemplate;

    @Value("${server.port}")
    String port;


    @RequestMapping("/login")
    public String login(){
        return "welcome login!";
    }

    @RequestMapping("index")
    public String index(){
        return "welcome index!";
    }


    @ApiOperation(value="sayhi", notes="say hi interface")
    @ApiImplicitParam(name = "say", value = "hi", paramType = "query", required = true, dataType = "String")
    @RequestMapping("/hi")
    public String home(@RequestParam(value = "name", defaultValue = "forezp") String name) {
        logger.info("calling trace service-hi ");
        return restTemplate.getForObject("http://localhost:1220/miya", String.class);
    }


    @RequestMapping("/info")
    public String info(){
        logger.info("calling trace service-hi ");
        return "i'm service-hi";
    }
}
